﻿
@{
    ViewBag.Title = "批量锁定";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var levels = ViewBag.QLevels as List<IOA.MES.DataAccess.VModel.VQLevel>;
    var sites = ViewBag.SiteTypes as List<KeyValuePair<int, string>>;
}
@model IOA.MES.DataAccess.VModel.VDowngrade

@section Contents{
    <style>
        .layui-form-label {
            width: 120px;
        }

        .layui-form-item .layui-input-inline {
            width: 300px;
        }

        .red {
            color: red;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 30px;">
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.CurSite">当前站点：</label>
            <div class="layui-input-inline">
                <select name="curSite">
                    @foreach (var item in sites)
                    {
                        <option value="@item.Key">@item.Value</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.LockSite">锁定站点：</label>
            <div class="layui-input-inline">
                <select name="lockSite">
                    @foreach (var item in sites)
                    {
                        <option value="@item.Key">@item.Value</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.LockCodes">锁定条码：</label>
            <div class="layui-input-inline">
                <textarea class="layui-textarea" required lay-verify="required" name="codes" value="" placeholder="请输入条码/箱号/柜号"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" v-html="lang.Field.LockDesc">锁定说明：</label>
            <div class="layui-input-inline">
                <textarea class="layui-textarea" name="lockReason" value="" placeholder="请输入解锁说明"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="text-align:center;padding-top: 20px;">
            <button class="layui-btn layui-btn-primary" onclick="parent.layer.close(parent.layer.getFrameIndex(window.name));"><i class="layui-icon">&#xe616;</i>取消</button>
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit"><i class="layui-icon">&#xe61a;</i>锁定</button>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['form', 'layer', 'index', 'laydate'], function () {
                var layer = layui.layer,
                    form = layui.form;

                form.on('submit(submit)', function (data) {
                    console.log(data.field);
                    var codes = data.field.codes.trim().split('\n');
                    if (codes.length <= 0) {
                        layer.msg("请至少输入1个条码", { icon: 5 });
                        return false;
                    }
                    var loadId = layer.load();
                    $.ajax({
                        url: "/Quality/BatchLock",
                        data: {
                            barCodes: codes,
                            curSite: data.field.curSite,
                            lockSite: data.field.lockSite,
                            lockReason: data.field.lockReason
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("锁定成功！", { icon: 6, time: 1000 }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
